package sample;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Srever {
    public static void main(String[] args) {
        String reply = null;
        ServerSocket server = null;
        Socket client = null;
        PrintWriter writer = null;
        ObjectInputStream obj = null;
        try {
            server = new ServerSocket(8886);
            client = server.accept();
            obj = new ObjectInputStream(client.getInputStream());
            User user = (User) obj.readObject();
            writer = new PrintWriter(new OutputStreamWriter(client.getOutputStream()));
            while (user != null) {
                if (user.getUsername().equals("bjsxt") && user.getPassword().equals("bjsxt")) {
                    reply = "登陆成功";
                } else {
                    reply = "用户名或密码错误";
                }
                user = (User) obj.readObject();
            }
            writer.println(reply);
            writer.flush();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                writer.close();
                obj.close();
                client.close();
                server.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}